/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DisponibilidadEjecutivo.java
 *
 * Created on Feb 1, 2009, 6:48:14 PM
 */
package interfaz;

import dominio.Empleado;
import dominio.Evento;
import integracion.ControlEmpleado;
import integracion.ControlEvento;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Maya
 */
public class DisponibilidadEjecutivo extends javax.swing.JFrame {

    ControlEmpleado controlEmpleado;
    ControlEvento controlEvento;
    Integer cedulaE;

    /** Creates new form DisponibilidadEjecutivo */
    public DisponibilidadEjecutivo(Integer cedulaE) {
        initComponents();
        this.cedulaE = cedulaE;
        this.cargarTablaEventosEjecutivo();
        this.setLocation(400, 200);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableDisponibilidad = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabelCedula = new javax.swing.JLabel();
        jLabelNombre = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "DISPONIBILIDAD DEL EJECUTIVO", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11), new java.awt.Color(0, 102, 204))); // NOI18N

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Iconos/agt_action_success.png"))); // NOI18N
        jButton1.setText("Listo");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTableDisponibilidad.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Evento", "Fecha", "Hora Inicio", "Hora Fin"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTableDisponibilidad);

        jLabel1.setText("Cedula:");

        jLabel2.setText("Nombre:");

        jLabelCedula.setText("cedula ejecutivo");

        jLabelNombre.setText("nombre ejecutivo");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 468, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelNombre)
                            .addComponent(jLabelCedula)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButton1)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabelCedula))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabelNombre))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 217, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed


    public void cargarTablaEventosEjecutivo() {
        try {
            List<Evento> eventos = this.consultarEventos();
            List<Empleado> ejecutivos = this.consultarEjecutivos();
            DefaultTableModel dm = new DefaultTableModel();

            dm.addColumn("Evento");
            dm.addColumn("Fecha");
            dm.addColumn("Hora Inicio");
            dm.addColumn("Hora Fin");

            for (Evento evento : eventos) {
                Vector tabla = new Vector();
                for (Empleado ejecutivo : ejecutivos) {
                    if (ejecutivo.getCedula().equals(cedulaE)) {
                        if (evento.getEjecutivoCedula().equals(ejecutivo.getCedula())) {
                            this.jLabelCedula.setText(ejecutivo.getCedula().toString());
                            this.jLabelNombre.setText(ejecutivo.getNombre() + " " + ejecutivo.getApellido());
                            tabla.addElement(evento.getDescripcion());
                            tabla.addElement(evento.getFecha());
                            tabla.addElement(evento.getHoraInicio());
                            tabla.addElement(evento.getHoraFin());
                            dm.addRow(tabla);
                        }
                    }
                }
                this.jTableDisponibilidad.setModel(dm);
            }

        } catch (SQLException ex) {
            Logger.getLogger(NuevaCotizacion.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private List<Empleado> consultarEjecutivos() throws SQLException {
        List<Empleado> empleados = null;
        try {
            controlEmpleado = new ControlEmpleado();
            empleados = controlEmpleado.consultarEjecutivos();
            return empleados;

        } catch (IOException ex) {
            Logger.getLogger(InformacionSistema.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(InformacionSistema.class.getName()).log(Level.SEVERE, null, ex);
        }
        return empleados;
    }

    private List<Evento> consultarEventos() throws SQLException {
        List<Evento> eventos = null;
        try {
            controlEvento = new ControlEvento();
            eventos = controlEvento.consultarEventos();
            return eventos;

        } catch (IOException ex) {
            Logger.getLogger(InformacionSistema.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(InformacionSistema.class.getName()).log(Level.SEVERE, null, ex);
        }
        return eventos;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabelCedula;
    private javax.swing.JLabel jLabelNombre;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableDisponibilidad;
    // End of variables declaration//GEN-END:variables
}
